<?
/*
 * scrumbrella - Scrum board.
 *
 * Copyright (C) 2009  Gustavo N. Borgoni <gborgoni@voicemedia.com.ar>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

require_once("layout_config.php");
require_once("PHPTAL.php");

include("include/permission.php");
include("include/project.php");
include("include/html_utils.php");
include("layout_config.php");

// Check for user logged in
$user_id = permission_redirect_user("index.php");

	$_SESSION['selected'] = 0;

	if ($_SERVER['REQUEST_METHOD'] == "POST") {
		$_SESSION['project'] = $_REQUEST['project'];
	}

	// Load the template
	$temp = new PHPTAL('templates/home.xhtml');

	$temp->theme      = 'default';
	$temp->bt_select  = _("Select");
	$temp->prj_title  = _("Project");
	$temp->prj_select = _("Select project");
	$temp->err_select = _("Please select a project");

	// Project grid
	$temp->name     = _("Name");
	$temp->sprints  = _("Last sprint");
	$temp->role     = _("Your Role");
	$temp->backlog  = _("Project backlogs");
	$temp->progress = _("Progress");
	$temp->msg      = 0;
	$temp->prjgrid_title = _("Projects where you are involved");
	$temp->pendings_title = _("Pendings for estimate");
	$temp->mypendings_title = _("My pendings");

	$projects = project_list_byuser($user_id);
	if (!$projects) {
		$temp->projects = 0;
		$temp->msg      = 1;
		$temp->message  = _("You have not project asigned");
	} else {
		$i=0;
		foreach ($projects AS $project) {
			if ($class == 'grid_item_cebra') {
				$class = 'grid_item';
			} else {
				$class = 'grid_item_cebra';
			}

			if ($_SESSION['project'] == $project['id_project']) {
				$prj[$i]['class'] = "grid_selected";
			} else {
				$prj[$i]['class'] = $class;
			}

			$prj[$i]['name']        = $project['name'];
			$prj[$i]['id_project']  = $project['id_project'];
			$prj[$i]['sprint']      = count(project_get_lastsprint($project["id_project"]));
			$prj[$i]['member']      = count(project_get_members($project["id_project"], "Team Member"));
			$prj[$i]['role']        = permission_role_byid($project["id_role"]);
			$prj[$i]['pbacklog']    = project_backlogs_total($project["id_project"]);
			$prj[$i]['progress']    = project_progress($project["id_project"]);
			$prj[$i]['id_progress'] = "progressbar_".$project['id_project'];
			$i++;
		}
	}
	$temp->projects_grid = $prj;
	$temp->flash_msg = _("Do you need to install flash player");
	
	// Load project list
	if ($_SESSION['project'] > 0) {
		$projects = html_select_projectbyuser($user_id, $_SESSION['project']);
	} else {
		$projects = html_select_projectbyuser($user_id);
	}
	$temp->projects = $projects;

	// Load the template
	try 
	{
		echo $temp->execute();
	}

	catch(Exception $e)
	{
		echo $e;
	}
?>
